//
// Description: 594. 最长和谐子序列
// Created by Loading on 2021/11/20.
//

#include <bits/stdc++.h>

using namespace std;

int findLHS(vector<int> &nums) {
    int res = 0;
    unordered_map<int, int> count;

    for (auto &x : nums) {
        count[x]++;
    }
    for (auto &x : nums) {
        if (count[x - 1] != 0) {
            res = max(res, count[x - 1] + count[x]);
        }
    }

    return res;
}

int main() {
    vector<int> nums = {1, 3, 2, 2, 5, 2, 3, 7};
    int res = findLHS(nums);
    cout << res << endl;

    return 0;
}